<template>
	<view>
		<button @click="goLogin">登录</button>
		<button @click="logout">退出登录</button>
		<button @click="goUserInfo">个人中心</button>
		<view>
			<uni-list>
				<uni-list-item
					v-for="item in listArr"
					:key="item._id"
					:title="item.title"
					:note="item.content"
					:thumb="item.userid[0].avatar_file.url"
					thumb-size="lg"
					:rightText="item.userid[0].username"
				></uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	import { mutations } from "@/uni_modules/uni-id-pages/common/store.js"
	const db = uniCloud.database()
	// const dbCmd = db.command

	export default {
		name: 'demo1',
		data() {
			return {
				listArr: []
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData() {
				// db.collection('cloudDemo').get().then(res => {
				// 	console.log(res, 'res')
				// 	this.listArr = res.result.data
				// })
				let artTemp = db.collection('cloudDemo').field('title,content,userid,posttime').getTemp()
				let userTemp = db.collection('uni-id-users').field('_id,username,avatar_file,nickname').getTemp()
				db.collection(artTemp, userTemp).orderBy('_id desc').limit(1).get().then(res => {
					console.log(res, 'res')
					this.listArr = res.result.data
				})
			},
			goLogin() {
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
				})
			},
			goUserInfo() {
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/userinfo/userinfo'
				})
			},
			logout() {
				mutations.logout()
			}
		}
	}
</script>

<style>

</style>
